package com.cgwx.commonutils.math.function;

/**
 * @author GaoWei
 * @Date 2021/8/6 - 9:26
 */
public class MaxFunction implements Function
{
    @Override
    public double of(double[] d, int numParam)
    {
        if (numParam == 0)
        {
            return 1.7976931348623157E+308D;
        }
        double max = -1.79769313486231E+308D;
        for (int i = 0; i < numParam; i++)
        {
            if (d[i] > max)
            {
                max = d[i];
            }
        }
        return max;
    }

    @Override
    public boolean acceptNumParam(int numParam)
    {
        return numParam >= 0;
    }

    public String toString()
    {
        return "max(x1, x2, ..., xn)";
    }
}
